import * as authUserRoleApi from '@/api/auth/authUserRoleApi.js'
import * as storage from '@/util/storage.js'

let menuList = []

export function listUserRole() {
	authUserRoleApi.listUserRole({
		userId: storage.getUserId(),
		type: '3'
	}).then(res => {
		const {
			data
		} = res
		if (data) {
			menuList = data
		}
	})
}

export function isSystemManager() {
	for (const menu of menuList) {
		if (menu.roleId === 1) {
			return true
		}
	}
	return false
}


export function isCompanyManager() {
	for (const menu of menuList) {
		if (menu.roleId === 2) {
			return true
		}
	}
	return false
}

export function isDeptManager() {
	for (const menu of menuList) {
		if (menu.roleId === 3) {
			return true
		}
	}
	return false
}


export function listWebsiteModel(that) {
	const list = [{
		label: that.$t('user'),
		value: 'user'
	}]
	if (isSystemManager()) {
		list.push({
			label: that.$t('system'),
			value: 'system'
		})
	}
	if (isCompanyManager()) {
		list.push({
			label: that.$t('company'),
			value: 'company'
		})
	}
	if (isDeptManager()) {
		list.push({
			label: that.$t('dept'),
			value: 'dept'
		})
	}
	return list
}
